package cn.skcks.dao;

import cn.skcks.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserDao {
	// 根据 id 查询用户
	@Select("SELECT id,name,pwd FROM user")
	@Results(
			@Result(property = "password", column = "pwd")
	)
	List<User> getUsers();

	// 当有多个参数时, 所有参数前面必须添加 Param 注解
	@Select("SELECT id,name,pwd as password FROM user WHERE id = #{id}")
	User getUserByID(@Param("id") int id);

	@Insert("INSERT INTO user(id,name,pwd) VALUES(#{id},#{name},#{password})")
	int addUser(User user);

	@Update("UPDATE user set name=#{name},pwd=#{password} WHERE id = #{id}")
	int updateUser(User user);

	@Delete("DELETE FROM user where id = #{id}")
	int deleteUser(@Param("id") int id);
}